﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using ICeFramework.Common.DataLayer.Enums;

namespace ICeFramework.Common.Configuration
{
    public class ConnectionElement : ConfigurationElement
    {
        #region public ConnectionElement()
        /// <summary>
        /// Initializes a new instance of the <b>ConnectionElement</b> class.
        /// </summary>
        public ConnectionElement()
        {
        }
        #endregion

        #region public String Name
        /// <summary>
        /// Get/Sets the Name of the ConnectionElement
        /// </summary>
        /// <value></value>
        [ConfigurationProperty("name", IsRequired = true)]
        public String Name
        {
            get
            {
                return (String)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }
        #endregion

        #region public ServerType ServerType
        /// <summary>
        /// Get/Sets the ServerType of the ConnectionElement
        /// </summary>
        /// <value></value>
        [ConfigurationProperty("serverType")]
        public ServerType ServerType
        {
            get
            {
                return this["serverType"] != null ? (ServerType)this["serverType"] : ServerType.NotAvailable;
            }
            set
            {
                this["serverType"] = value;
            }
        }
        #endregion

        #region public bool IsDefault
        /// <summary>
        /// Get/Sets the IsDefault of the ConnectionElement
        /// </summary>
        /// <value></value>
        [ConfigurationProperty("default")]
        public bool IsDefault
        {
            get
            {
                return this["default"] != null ? (bool)this["default"] : false;
            }
            set
            {
                this["default"] = value;
            }
        }
        #endregion

        #region public String RemoteUrl
        /// <summary>
        /// Get/Sets the RemoteUrl of the ConnectionElement
        /// </summary>
        /// <value></value>
        [ConfigurationProperty("remoteUrl")]
        public String RemoteUrl
        {
            get
            {
                return (String)this["remoteUrl"];
            }
            set
            {
                this["remoteUrl"] = value;
            }
        }
        #endregion

        [ConfigurationProperty("remoteUserName")]
        public String RemoteUserName
        {
            get
            {
                return (String)this["remoteUserName"];
            }
            set
            {
                this["remoteUserName"] = value;
            }
        }

        [ConfigurationProperty("remotePassword")]
        public String RemotePassword
        {
            get
            {
                return (String)this["remotePassword"];
            }
            set
            {
                this["remotePassword"] = value;
            }
        }

        #region private ServerType GetServerType(string typeStr)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="typeStr"></param>
        /// <returns></returns>
        private ServerType GetServerType(string typeStr)
        {
            try
            {
                return (ServerType)Enum.Parse(typeof(ServerType), typeStr, true);
            }
            catch
            {
                return ServerType.NotAvailable;
            }
        }
        #endregion
    }
}
